package com.example.mylearn.tree;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.junit.jupiter.api.Test;

public class Tree1 {




    @Setter
    @Getter
    @NoArgsConstructor
    static class Node<T>{

        T data;
        Node<T> left;
        Node<T> right;


        public Node(T data) {
            this.data = data;
        }
    }


    public void preOrder(Node root) {
        if (root != null) {
            System.out.print(root.data);
            preOrder(root.left);
            preOrder(root.right);
        }
    }

    public void inOrder(Node root) {
        if (root != null) {
            inOrder(root.left);
            System.out.print(root.data);
            inOrder(root.right);
        }
    }


    public void postOrder(Node root) {
        if (root != null) {
            postOrder(root.left);
            postOrder(root.right);
            System.out.print(root.data);
        }
    }


    @Test
    public void testTree() {
        Node<String> A = new Node<String>("A");
        A.left = new Node<>("B");
        A.right = new Node<>("C");


        A.left.left = new Node<>("D");
        A.left.right = new Node<>("E");

        A.right.left = new Node<>("F");
        A.right.right = new Node<>("G");

        A.left.left.left = new Node<>("H");

        preOrder(A);
        System.out.println();
        inOrder(A);
        System.out.println();
        postOrder(A);

    }








}





